package com.semidata.rtd.core.http.server;

import java.nio.charset.Charset;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.util.CharsetUtil;

public class HttpSession {

	private ChannelHandlerContext ctx;
	private HttpRequest request;
	private ByteBuf buffer;
	private HttpResponse response;
	private long timestamp;

	public HttpSession(ChannelHandlerContext ctx, HttpRequest request, ByteBuf buffer) {
		this.timestamp = System.currentTimeMillis();
		this.request = request;
		this.ctx = ctx;
		this.buffer = buffer;
		this.response = new HttpResponse(ctx, request);
	}
	
	public ChannelHandlerContext getCtx() {
		return ctx;
	}

	public HttpRequest getRequest() {
		return request;
	}

	public String getBody(Charset charset) {
		return buffer.toString(charset);
	}
	
	public String getBody() {
	    return getBody(CharsetUtil.UTF_8);
	}

	public ByteBuf getBuffer() {
	    return buffer;
	}
	
	public HttpResponse getResponse() {
		return response;
	}

	public long getTimeStamp() {
		return timestamp;
	}
}
